<template>
  <div class="store_container">
    <div class="image">
      <el-image
        style="height:100%;width:inherit"
        :src="image_url"
        fit="cover"
        class="el_image"
      ></el-image>
      <div class="front_title">
        <p>门店</p>
        <p>
          三两已经在烟台开了数十家门店，为烟台人民提供了便利、干净、美味的酱香包
        </p>
      </div>
    </div>

    <div class="detail_store">
      <p class="title01">三两分店</p>
      <p class="title02">BRANCH STORE</p>
      <p class="title03"></p>
      <p class="title04">
        以酱香包为代表“三两”始终坚持，“健康、美味、极致”的产品主义，不断颠覆，不断死磕，<br />
        只为让你吃上一口最地道的正宗胶东酱香包。
      </p>
      <div class="store_show">
        <div
          v-for="(item, index) in storeList"
          :key="index"
          class="store_show_item"
        >
          <div class="item_icon">
            <el-image
              :src="item_icon_url"
              fit="cover"
              class="item_icon_img"
            ></el-image>
          </div>
          <div class="city_address">
            <span class="city">{{ item.area }}</span>
            <span class="address">{{ item.addr }}</span>
          </div>
          <p class="item_icon_content">{{ item.addr }}</p>
          <p class="item_icon_content">{{ item.opentime }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { fetchStore } from "../api/api";
import moment from "moment";
export default {
  data() {
    return {
      item_icon_url: require("../assets/store/icon/图层45.png"),
      image_url: require("../assets/store/image/banner_no_content.jpg"),
      storeList: []
    };
  },
  mounted() {
    this.initScroll();
  },
  created() {
    this.getStoreList();
  },
  // watch: {
  //   storeList() {
  //     handler(val) {

  //     }
  //   }
  // },
  methods: {
    // 门店信息开业时间格式化
    storeOpenTimeFormat() {
      for (let i = 0; i < this.storeList.length; i++) {
        this.storeList[i].opentime = moment(this.storeList[i].opentime).format(
          "YYYY年MM月DD日"
        );
      }
    },
    // 获取门店信息
    getStoreList() {
      fetchStore().then(res => {
        // eslint-disable-next-line no-console
        console.log(res.data.results);
        this.storeList = res.data.results;
        this.storeOpenTimeFormat();
      });
    },
    initScroll() {
      document.documentElement.scrollTop = 0;
    }
  }
};
</script>

<style lang="less" scoped>
.store_container {
  p {
    cursor: default;
  }
  span {
    cursor: default;
  }

  .image {
    width: 100%;
    position: relative;

    .front_title {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      animation: front_title 2s;
      cursor: default;

      @keyframes front_title {
        from {
          opacity: 0;
          transform: translate(-50%, 50%);
        }
      }

      p {
        color: #ffffff;
        margin: 0;
        text-align: center;

        &:first-child {
          font-size: 48px;
          font-weight: bold;
          margin-bottom: 23px;
        }
        &:last-child {
          font-size: 16px;
          font-weight: 400;
        }
      }
    }
  }

  .detail_store {
    margin-top: 65px;

    .title01 {
      margin: 0;
      font-size: 36px;
      font-weight: bold;
      color: #333333;
      text-align: center;
    }
    .title02 {
      margin: 0;
      font-size: 20px;
      font-weight: 500;
      color: #231815;
      text-align: center;
      margin-top: 17px;
    }
    .title03 {
      width: 36px;
      height: 2px;
      background: #2f2d2c;
      margin: auto;
      margin-top: 20px;
    }
    .title04 {
      margin: 0;
      font-size: 16px;
      font-weight: 400;
      color: #4c4948;
      text-align: center;
      margin-top: 29px;
    }

    .store_show {
      width: 1200px;
      margin: 0 auto;
      display: flex;
      flex-wrap: wrap;
      margin-top: 43px;

      .store_show_item {
        box-sizing: border-box;
        padding: 27px 0 0 0;
        width: 378px;
        height: 227px;
        margin-right: 33px;
        margin-bottom: 23px;
        border: 1px solid #dcdcdc;

        &:nth-child(3n) {
          margin-right: 0;
        }

        .item_icon {
          position: relative;
          margin: 0 auto;
          width: 63px;
          height: 63px;
          border-radius: 50%;
          background: #e13727;

          .item_icon_img {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
          }
        }

        .city_address {
          display: flex;
          flex-wrap: nowrap;
          margin: 0 auto;
          width: fit-content;
          margin-top: 20px;

          span {
            display: block;
            margin-right: 5px;
            font-size: 20px;
            font-weight: 400;

            &:last-child {
              margin-right: 0;
            }
          }
        }

        p {
          margin: 0;
          text-align: center;
          font-size: 16px;
          font-weight: 400;
          opacity: 0.6;

          &:nth-last-child(2) {
            margin-top: 20px;
          }

          &:last-child {
            margin-top: 5px;
          }
        }
      }
    }
  }
}
</style>
